#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;

string word_to_number(const string& word) {
    unordered_map<string, string> numbers = {
        {"zero", "0"}, {"one", "1"}, {"two", "2"}, {"three", "3"},
        {"four", "4"}, {"five", "5"}, {"six", "6"}, {"seven", "7"},
        {"eight", "8"}, {"nine", "9"}
    };
    auto it = numbers.find(word);
    if (it != numbers.end()) {
        return it->second;
    }
    return "";
}

bool is_prime(int n) {
    if (n <= 1) {
        return false;
    }
    if (n == 2) {
        return true;
    }
    if (n % 2 == 0) {
        return false;
    }
    int max_divisor = static_cast<int>(sqrt(n));
    for (int d = 3; d <= max_divisor; d += 2) {
        if (n % d == 0) {
            return false;
        }
    }
    return true;
}

void find_nearest_prime_number(const vector<string>& words) {
    string number_str;
    for (const auto& word : words) {
        string num = word_to_number(word);
        if (!num.empty()) {
            number_str += num;
        }
    }

    if (number_str.length() != 3 || !all_of(number_str.begin(), number_str.end(), ::isdigit)) {
        cout << "Wrong input" << endl;
        return;
    }

    int number = stoi(number_str);

    if (is_prime(number)) {
        cout << number << endl;
        return;
    }

    int lower = number - 1;
    int upper = number + 1;
    while (true) {
        if (is_prime(lower)) {
            cout << lower << endl;
            return;
        } else if (is_prime(upper)) {
            cout << upper << endl;
            return;
        }
        lower--;
        upper++;
    }
}

int main() {
    cout << "Введите три слова: ";
    string input;
    getline(cin, input);
    vector<string> input_words;
    string word;
    for (char c : input) {
        if (c == ' ') {
            if (!word.empty()) {
                input_words.push_back(word);
                word.clear();
            }
        } else {
            word += c;
        }
    }
    if (!word.empty()) {
        input_words.push_back(word);
    }

    find_nearest_prime_number(input_words);
    return 0;
}